/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package vue;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import utiles.K;

/**
 *
 * @author julien
 */
public class PlacementElementCarte extends JFrame{

    public PlacementElementCarte() {
        super();
	this.build();
    }

    private void build() {
        this.setTitle("Placement des élément de la carte");
        this.setSize(800,600);
        this.setLocationRelativeTo(null);
        this.setResizable(false);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
        this.setLayout(new BorderLayout ());
        
        JPanel carte = new JPanel();
        carte.setLayout(new GridLayout(K.LONG, K.LARG));
        for (int i = 0; i < K.LONG; i++) {
            for (int j = 0; j < K.LARG; j++) {
               JLabel position = new JLabel(i + " " + j);
               Border paddingBorder = new EmptyBorder(0,0,0,0);
               Border border = BorderFactory.createLineBorder(Color.BLACK);
               position.setBorder(BorderFactory.createCompoundBorder(border,paddingBorder));
               carte.add(position);
            }
        }
        
        JPanel verticalBox = new JPanel();
        verticalBox.setLayout(new BorderLayout ());
        
        JButton creer = new JButton("Créer");
        Dimension d = new Dimension(100,50);
        creer.setPreferredSize(d);
        
        JLabel titre = new JLabel("Liste des élements");
        
        JList list = new JList( K.ELEMENTS );
        ListSelectionListener listSelectionListener = new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent listSelectionEvent) {
              boolean adjust = listSelectionEvent.getValueIsAdjusting();
                if (!adjust) {
                    JList list = (JList) listSelectionEvent.getSource();
                    int selections[] = list.getSelectedIndices();
                    Object selectionValues[] = list.getSelectedValues();
                    for (int i = 0, n = selections.length; i < n; i++) {
                        System.out.println(selectionValues[i] + " ");
                    }
                }
            }
        };
        list.addListSelectionListener(listSelectionListener);
        
        verticalBox.add("North", titre);
        verticalBox.add("Center", list);
        verticalBox.add("South", creer);
        
        this.add("Center", carte);
        this.add("East",verticalBox);

            
    }
}
